package com.teach.controller;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
public class LiveController {

    @RequestMapping("/initLive/{uid}")
    public Map initLive(@PathVariable String uid){

        Date current = new Date();
        long currentTime = current.getTime();
        //链接有效期1小时
        long endTime = (currentTime + 3600*1000)/1000;
        //endTime-->16进制
        String txTime = Long.toHexString(endTime);
        //推流配置中的主KEY
        String key = "fa0bb4807c73253a584bb26f84fd2316";
        String txSecret = DigestUtils.md5Hex(key + uid + txTime);
        //推流的域名  腾讯云自己生成的
        String pushUrl = "webrtc://174793.push.tlivecloud.com/live/"+uid+"?txSecret="+txSecret+"&txTime="+txTime;
        String pullUrl = "webrtc://ngw.huangyj.cn/live/"+uid;

        Map map = new HashMap();
        map.put("pushUrl",pushUrl);
        map.put("pullUrl",pullUrl);
        return map;
    }

}
